
TO WORD WRAP THIS TEXT:

Click Edit on this screen's above toolbar and then click on Word Wrap.


TK3 PROGRAMMING NOTES - updated 05NOV04

Some of this information may update that given in the published EPE TK3 text.

Always check the Updates file for any information that affects these notes. It is normally issued whenever an update to TK3 is released and is accessible via the "Updates" button at the bottom of the main TK3 screen.

Before any attempt at communication with the PIC is made from any function button, and if the Verifying option is in use (see Verifying notes viewable via the Check PCB button on the main screen), a check is made to determine if the printer port cable is connected and the PCB power is on. A message box appears if either of these conditions is false.

The PIC may be programmed via the Programming section's Send HEX   button - the command codes are immediately sent to the PIC.

The facility to program PICs from an OBJ file has been dropped since V2.0. If you wish to use an OBJ file, first convert it to HEX via the Convert OBJ to HEX button.

If the Verifying option is in use, a check that the sent and readback codes are the same is then made. If it is not the same, a preliminary error message screen can be displayed which gives brief reasons why there should be differences and possible remedies for them. From this screen, a Show Errors button can be clicked to display the nature of the differences.

There are two forms for this display. When the Verify routine is entered a check on the Configuration value held in the PIC is made. If the readback value has logic 1 in each bit position, or logic 0 in each bit position, or the Configuration value otherwise indicates that one or more of the PIC's code protection bits are On, the value is displayed on its own and verification is not attempted.

If the Config check is completed successfully and different sent/readback values result, the screen displays both values side by side in sequence from beginning to end.

The listed sequence is for interest only. If differences exist, and the readback column shows a variety of values, send the entire code to the PIC again (note that partial sending of codes cannot be done since the PIC's address counter is always reset prior to code being sent). It is worth noting that the author has never experienced true verification errors when a PIC is programmed from a correctly working system and often keeps the Verification option disabled.

However, it is appropriate to comment that on one occasion a single verification error was repeatedly reported. Extensive examination eventually revealed that the PIC itself was faulty. One program memory location was found to have its most significant bit permanently set high. This did not matter if the code itself was required to set that bit high. If the bit was intended to be set low, though, a verification error at that location would be reported.

If Verification is On and a problem is reported, a "Send Again" button appears which enables you to try again. If an error repeatedly occurs in the same location (as in the above paragraph), use the Erase PIC option, readback the PIC to an ASM file and examine the file. If the body of the code shows any statement that is not "NO CODE - 63" suspect a faulty PIC (ignore ORG and END statements). A similar test can be done by using the Clear Code Protect option in the Configuration screen.  

TEST HEX

The Test HEX button allows Richard Hinckley's excellent PIC Breakpoint debugging facility to be accessed (must be installed separately). Details of this were published in EPE Oct '03.

PnM HEX VIEW

Provides access to Andrew Jarvis' Hex check facility discussed in EPE OCT '04.

HEX DECODE BUTTON

This loads the current HEX file into a screen through which you can click on each line of hex code to see the commands that the codes within that line represent.

HEX MAKE-UP NOTES

MPASM HEX files are formatted in what is known as the Intel style (believed to be known as INHX8M), in which address and other formatting values are included and can be read via a text editor. They are formatted so that several commands are sequenced on the same line, with the structure as for the following example (the spaces between the letter groups are omitted in actual hex files):

:NN AAAA RR MMLL MMLL MMLL MMLL CC TT

in which

":"      = record start character
"NN"     = byte quantity in line as hex value
"AAAA"   = address of first byte in hex *
"RR"     = record type in hex (normally 00 except for last which is 01 - see below)
"MMLL"   = data bytes in order of MMLL in hex
"CC"     = Check Sum in hex
"TT"     = line terminator (carriage return, line feed)

Checksum is calculated as:

Sum      = byte count + address hi + address lo + record type +
           (sum of all data bytes on the line)

Checksum = (-Sum) AND 255

* The AAAA address value is twice that of the actual command count address.

There can be more data values held on each line than are shown here, TK3 normally uses 16 per line when compiling hex files, in common with most assemblers.

Note that other versions of hex files exist in which the data is held in a different order. For example, whereas for MPASM the above MMLL bytes are held in order of MSB/LSB, they might be held in order of LSB/MSB in some other types of hex file. For example, whilst TASM HEX files have never been documented in EPE, the original TASM assembly software used for the EPE Simple PIC Programmer of 1996, PIC Tutorial of Mar-May 1998, and the current (as at April 2001) PICtutor CD-ROM, could be told to generate them, in which the byte order is LSB/MSB.

Only hex files in the MPASM/Intel format can be processed by TK3.

Also note that although TK3 generates the check sum when compiling hex files, it does not use the check sum when sending hex file data to the PIC - all HEX files are assumed to hold the correct data, as are all OBJ files.

It has come to light that some other record types exist (see "RR" above) - thank you originally to Malcolm Wiles. Peter Hemsley clarifies by saying that:

   00 = Data record
   01 - End of file record
   02 - Segment address record
   04 - Linear address record

and that "the last two types are concerned with 32-bit addressing and are not used in INHX8M format files". Thank you Peter!

ADDING YOUR OWN NOTES

These notes are displayed via an "Active" text editor and you may add your own notes to them, saving them to disk in the usual way.
